<?php
	include_once(PRODIR."/structure/mysqlTableStruct.php");
	include_once("abstractStruct.php");
	include_once(PRODIR."/function/abstractBaseFunction.php");
	
	function __autoload($class_name) {
 	   require_once PRODIR.'/function/'.$class_name.'.php';
	}
	
	//var_dump($mySql);
	class createFileStruct{
		
		public  $fieldObject;	//句柄
		private $fileTemplate;	//模板字段
		//会被加入的函数的集合
		private $function = array();		
		function __construct(){
			$mySql = new mySqlTableStruct(array(
				'host'	=> 'localhost',
				'user'	=> 'root',
				'password'=> '',
				'db'		=> 'ysw',
				'table'		=> 'wp_posts'
			));
		//	$this->fieldStruct = $mySql->getField();
			$this->fieldObject = &$mySql;
			
			if(!($this->getTableFiled())){
				die("数据结构为空");	
			}
	
		}
		
		function addFunction(baseFunction $function){
			$function->setTableStruct($this->fieldObject);
			//$function->setTableFiled($this->getTableFiled());
			$this->function[] = &$function;
			return $this;
		}
		function getTableFiled(){
			return $this->fieldObject->getField();
		}
		
		
		function defultsFileTemplate(){
			return "class [className]{\n
					[classArg]<br>
					[classContent]<br>
			}";	
		}
		function create(){
			//replace Class Name			
			$this->replaceClassName();
			
			$results = false;
			foreach($this->function as $value){
					$results .= $value->getResults();	
			}
			$this->replaceClassContent($results);
			//print_r($results);
			print_r($this->fileTemplate);
		}		
		function replaceClassName(){
			return	$this->replace('[className]',$this->getClassName());
		}
		function replaceClassContent($content){
			return $this->replace('[classContent]',$content);	
		}
		function getClassName(){
			$className = $this->fieldObject->getTable();		
			return ucfirst($className).'Module';
		}
		function replace($search,$replace){
				$this->fileTemplate = str_replace($search,$replace,$this->getFileTemplate());	
				return $this;			
		}		
		function getFileTemplate(){
			if(is_null($this->fileTemplate))
				$this->fileTemplate = $this->defultsFileTemplate();
			return $this->fileTemplate;	
		}
		
	}
	
	
	
?>